package com.aurora.source.util.netutil;

import com.aurora.source.constant.AuroraConstants;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.GsonBuilder;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @author: Lance
 * @description: Retrofit 工具类
 * @date: 2018/7/6 13:32
 */
public class RetrofitUtil {

    //服务路径
//    public static final String sUrl = "http://192.168.13.205:9999/OAFront/"; //测试
//    public static final String sUrl = "http://www.daobc.cn:9005/OAFront/"; //测试 此处的url必须要以“/”结尾，不然会抛异常
  //  public static final String sUrl = "http://chenchen.rsaurora.com.cn/"; //测试 此处的url必须要以“/”结尾，不然会抛异常

    private static Retrofit sRetrofit;
    private static OkHttpClient sOkHttpClient;

    protected static Retrofit getRetrofit() {
        if (sRetrofit == null) {
            if (sOkHttpClient == null) {
                sOkHttpClient = OkHttpUtil.getOkHttpClient();
            }
            sRetrofit = new Retrofit.Builder()
                    .baseUrl(AuroraConstants.SOURCE_URL)
                    .addConverterFactory(GsonConverterFactory.create(
                            new GsonBuilder()
                                    .setLenient()
                                    .serializeNulls()
                                    .setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create()))
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .client(sOkHttpClient)
                    .build();
        }
        return sRetrofit;
    }
}
